import requests
import hashlib
import json
def test_login():
    #  -------登录-------------
    username = 'jsh'  # 初始化密码账号
    password = '123456'
    md5 = hashlib.md5(password.encode())  # 创建md5加密
    password_md5 = md5.hexdigest()  # 调用方法hexdigest()加密

#
# # -------构建请球头---------
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 Edg/118.0.2088.46',
        'Content-Type': 'application/json;charset=UTF-8'
    }
# # -------构建url-----------
    url_base = r'http://192.168.253.128:3000/'
    url_log = url_base + r'/jshERP-boot/user/login'
# -------构建data----------
    data_log = {"loginName": username, "password": password_md5}
# -------构建请求-----------
    resp = requests.post(url_log, json=data_log, headers=headers)
# -------响应数据-----------
    token = resp.json()['data']['token']  # 提取token
    print(token)
# -------------系统管理——角色管理——新增----------------------
# name = '1212'
# type = '全部数据'
# # 构造请求头
# headers['X-Access-Token'] = token  # 获取token值
# # 构造 url
# url_role_add = url_base + r'/jshERP-boot/role/add'
# # 构造 data
# data_add = {"name": name, "type": type}
# # 发送请求
# resp = requests.post(url_role_add, json=data_add, headers=headers)
# # 获取响应
# print(resp.text)
# # ------------系统管理——角色管理-修改------------
# # 数据添加
# id = '27'
# name = '1213'
# type = '全部数据'
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_modify = url_base + r'/jshERP-boot/role/update'
# # 构造 data
# data_modify = {"deleteFlag":"0","enabled":True,"id":id,"name":"name","tenantId":63,"type":"type"}
# # 发送请求
# resp = requests.put(url_modify,json=data_modify,headers=headers)
# # 响应
# print(resp.text)
# ------------系统管理——角色管理-删除-------------
# # 数据添加
# id = '30'
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_del = url_base + r'/jshERP-boot/role/delete'
# # 构造 data
# data_del = {"id":id}
# # 发送请求
# resp = requests.delete(url_del,params=data_del,headers=headers)
# # 响应
# print(resp.text)
# ------------系统管理——角色管理-查询-------------
# # 数据添加
# name = '1212'
# description = ""
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_del = url_base + r'/jshERP-boot/role/list'
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造 data
# search_dict = {"name":"1212","description":""}      # 单独定义字典
# search_str = json.dumps(search_dict)    # 字典转换成字符串
# data_role_query = {
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id', '', '', 'action', 'name', 'type', 'priceLimitStr', 'description', 'sort', 'enabled'],
#     'currentPage': 1,
#     'pageSize': 10
# }
#
# # 发送请求
# resp = requests.get(url_del,params=data_role_query,headers=headers)
# # 响应
# print(resp.text)
# ------------零售管理——零售出库-查询-------------
# 数据添加
# number = 'LSCK00000000684'
# materialParam = ''
# teyp = '出库'
# subType = "零售"
# roleType = "全部数据"
# organId = ""
# depotId = ""
# creator = ""
# accountId = ""
# status = ""
# remark = ""
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_ruery = url_base + r'/jshERP-boot/depotHead/list'
# # 构造请求头
# headers['X-Access-Token'] = token
# # 构造 data
# search_dict = {"number": "LSCK00000000684", "materialParam": "", "type": "出库", "subType": "零售",
#                "roleType": "全部数据", "organId": "", "depotId": "", "creator": "", "accountId": "", "status": "",
#                "remark": ""}  # 单独定义字典
# search_str = json.dumps(search_dict)  # 字典转换成字符串
# data_role_query = {
#     'search': search_str,
#     'column': 'createTime',
#     'order': 'desc',
#     'field': ['id', '', 'action', 'organName', 'number', 'materialsList', 'operTimeStr', 'userName', 'materialCount',
#               'totalPrice', 'getAmount', 'backAmount', 'status'],
#     'currentPage': 1,
#     'pageSize': 10
# }
#
# # 发送请求
# resp = requests.get(url_ruery, params=data_role_query, headers=headers)
# # 响应
# print(resp.text)
# # ------------系统管理——角色管理-删除-------------
# # 数据添加
# id = '264'
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_del = url_base + r'/jshERP-boot/depotHead/delete'
# # 构造 data
# data_del = {"id":id}
# # 发送请求
# resp = requests.delete(url_del,params=data_del,headers=headers)
# # 响应
# print(resp.text)


# # ------------零售管理—出库-修改------------
# 引用token
# headers['X-Access-Token'] = token
# # 数据添加
# organName = '123123'
# search_dict = {"id":5879,"type":"出库","subType":"零售","defaultNumber":"LSCK00000000812","number":"LSCK00000000812","createTime":"2024-01-12T08:15:56.000+0000","operTime":"2024-01-12 16:15:42","organId":92,"creator":63,"accountId":17,"changeAmount":5,"backAmount":0,"totalPrice":5,"payType":"现付","billType":'',"remark":'',"fileName":"","salesMan":'',"accountIdList":'',"accountMoneyList":'',"discount":'',"discountMoney":'',"discountLastMoney":0,"otherMoney":'',"deposit":0,"status":"0","purchaseStatus":"0","source":"0","linkNumber":'',"tenantId":63,"deleteFlag":"0","projectName":'',"organName":"organName","userName":'',"accountName":"账户1","allocationProjectName":'',"materialsList":"花西子假睫毛 10mm ","salesManStr":'',"operTimeStr":"2024-01-12 16:15:42","finishDebt":'',"depotHeadType":"零售出库","creatorName":"测试用户","contacts":'',"telephone":'',"address":'',"finishDeposit":'',"needDebt":'',"debt":-5,"materialCount":'',"hasFinancialFlag":False,"hasBackFlag":False,"realNeedDebt":'',"getAmount":5}
# search_str = json.dumps(search_dict)
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_modify = url_base + r'/jshERP-boot/depotHead/updateDepotHeadAndDetail'
# # 构造 data
#
# data_modify = {"info": search_str,
#                 "rows": "[{\"id\":\"6424\",\"name\":\"花西子假睫毛\",\"standard\":\"10mm\",\"model\":\"\",\"color\":\"黑色\",\"materialOther\":\"\",\"stock\":\"-1007\",\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":\"1\",\"unitPrice\":\"5\",\"allPrice\":\"5\",\"remark\":\"\",\"orderNum\":1,\"depotId\":\"14\",\"barCode\":\"1018\"}]"}
#
# # # 发送请求
# resp = requests.put(url_modify,json=data_modify,headers=headers)
# # # 响应
# print(resp.text)


# # ------------零售管理—出库-新增------------

# 添加数据
# number = 'LSCK0000000086'
# 引用token
# headers['X-Access-Token'] = token
# # 转换
# search1_dict = {"organId":92,"operTime":"2024-01-12 16:15:42","number":"number","payType":"现付","changeAmount":"5.00","getAmount":"5.00","backAmount":0,"accountId":17,"type":"出库","subType":"零售","defaultNumber":"number","totalPrice":5,"fileName":"","status":"0"}
# search_str = json.dumps(search1_dict)
# # 构造请求头
# headers['X-Access-Token'] = token  # 获取token值
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_role_add = url_base + r'/jshERP-boot/depotHead/addDepotHeadAndDetail'
# # 构造 data
# data_add = {
#     "info": search_str,
#     "rows":"[{\"id\":\"17050462867310654364\",\"name\":\"花西子假睫毛\",\"standard\":\"10mm\",\"model\":null,\"color\":\"黑色\",\"materialOther\":\"\",\"stock\":-1004,\"unit\":\"个\",\"snList\":\"\",\"batchNumber\":\"\",\"expirationDate\":\"\",\"sku\":\"\",\"operNumber\":1,\"unitPrice\":5,\"allPrice\":5,\"remark\":\"\",\"orderNum\":1,\"depotId\":\"14\",\"barCode\":\"1018\"}]"
# }
# # 发送请求
# resp = requests.post(url_role_add, json=data_add, headers=headers)
# # 获取响应
# print(resp.text)


# # # ------------零售出库-删除-------------
# # 数据添加
# id = '5867'
# # 构造 url
# url_base = r'http://192.168.253.128:3000/'
# url_del = url_base + r'/jshERP-boot/depotHead/delete'
# # 构造 data
# data_del = {"id":id}
# # 发送请求
# resp = requests.delete(url_del,params=data_del,headers=headers)
# # 响应
# print(resp.text)